package org.sanmao.wyj.service.impl;

import org.sanmao.wyj.controller.utils.Result;
import org.sanmao.wyj.dao.AdminDao;
import org.sanmao.wyj.domain.Admin;
import org.sanmao.wyj.service.AdminService;
import org.sanmao.wyj.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService  {

    @Autowired
    private AdminDao adminDao;

    @Override
    public String findAdminByUsernameAndPassword(Admin admin) {
        Admin isadmin = adminDao.findAdminByUsernameAndPassword(admin.getUsername(),admin.getPassword());
        if(isadmin != null){
            int adminid = isadmin.getAdminid();
            Map<String,Object> blankInfo = new HashMap<>();
            String token = JwtUtils.sign(adminid,blankInfo);
            return token;
        }
        else return null;
    }
}
